let express = require('express');
const { insertSql, updateSql, deleteSql } = require('../../utils');
let router = express.Router();
let connection = require('../dataBase');
const Result = require('../result');

router.post('/delete', function (req, res) {
  const sql = `delete from ${'`like`'} where accountId=${
    req.query.accountId
  } and commentId=${req.query.commentId}`;
  connection.query(sql, (err, data) => {
    if (err) {
      return new Result(res, 1200).fail();
    }
    return new Result(res, 200, data, '添加成功').success();
  });
});

router.post('/update', function (req, res) {
  const sql = req.body.id
    ? updateSql('`like`', req.body.id, req.body)
    : insertSql('`like`', req.body);
  connection.query(sql, (err, data) => {
    if (err) {
      return new Result(res, 1200).fail();
    }
    return new Result(res, 200, data, '添加成功').success();
  });
});

module.exports = router;
